﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SAIN.MVC.Controllers
{
    public class Membership
    {
        public Membership()
        {
        }
        public static string UserName
        {
            get
            {
                return ((BE.Security.Login.UsuarioBE)HttpContext.Current.Session["userid"]).sName;
            }
        }
        public BE.Security.Login.UsuarioBE CurrentUser
        {
            get
            {
                
                if (HttpContext.Current.Session["userid"] == null)
                    return new BE.Security.Login.UsuarioBE();
                else
                    return (BE.Security.Login.UsuarioBE)HttpContext.Current.Session["userid"];
            }
            private set
            {
                HttpContext.Current.Session["userid"] = value;
            }
        }
        public bool Login(string usuario, string password)
        {
            try
            {
                this.CurrentUser =  BC.Membership.UserBC.Login(usuario, password);
                if (this.CurrentUser.iUserId.HasValue && this.CurrentUser.iUserId < 1)
                {
                    this.CurrentUser = null;
                }
                return this.CurrentUser.iUserId.HasValue;
            }
            catch (Exception ex)
            {
                throw new Exception("Membership - Login - ", ex);
            }
        }

    }
}